let TX_ACCOUNT = "腾讯云账号";
let ACCOUNT_TYPE_ALI = 1;
let ACCOUNT_TYPE_TX = 2;
let docTypeArr = [{key:0,value:"三证合一"},{key:1,value:"企业营业执照"},{key:2,value:"组织机构代码证书"},
    {key:3,value:"社会信用代码证书"},{key:4,value:"应用后台管理截图（个人开发APP）"},{key:5,value:"网站备案后台截图（个人开发网站）"}
    ,{key:6,value:"小程序设置页面截图（个人认证小程序）"},{key:7,value:"商标注册书"},{key:8,value:"公众号设置页面截图（个人认证公众号）"}];
layui.use(['upload','element','table','layer','laydate','form','util'], function(){
    var table = layui.table,
        $ = layui.$,
        layer = layui.layer;
    var upload = layui.upload;
    var form=layui.form;
    var laydate = layui.laydate;
    var util = layui.util;
    let element = layui.element;

    var accountType;

    initAkInfo();

    // tab切换
    element.on('tab(smsTab)', function(data){
        layer.closeAll();
    });

    function initAkInfo() {
        $.get('/cdsmsmgr/smsAkInfo/getAkInfoByUser', {}, function (result) {
            if(result != null){
                if(result.resultContent != null){
                    var akInfo = result.resultContent;
                    if(akInfo){
                        accountType = akInfo.thirdAccountType == TX_ACCOUNT ? ACCOUNT_TYPE_TX : ACCOUNT_TYPE_ALI;
                        renderBusinessTable(accountType);
                        loadTemplateTypeOption(accountType);
                        renderSignTable(accountType);
                        renderTemplateTable(accountType);
                    }
                }
            }
        });
    }

    function loadTemplateTypeOption(accountType) {
        let options;
        if(ACCOUNT_TYPE_TX == accountType){
            options = [{key:"",value:"全部"},{key:"0",value:"普通短信"},{key:"1",value:"营销短信"}];
        }else {
            options = [{key:"",value:"全部"},{key:"0",value:"验证码"},{key:"1",value:"短信通知"},{key:"2",value:"推广短信"}];
        }
        let $opt_html;
        $.each(options, function (index, item) {
            $opt_html += "<option value='" + item.key + "'>" + item.value + "</option>";
        });
        $("#templateType").empty().append($opt_html);
        form.render('select');
    }

    loadSmsBusinessList();

    function renderBusinessTable(accountType){
        table.render({
            elem: '#smsBusinessTable'
            ,url: '/cdsmsmgr/smsBusiness/list'
            ,method: 'get'
            ,where: {accountType:accountType}
            ,title: '业务短信配置记录'
            ,cols: [[
                {type:'numbers',title: '序号'},
                {field: 'id', title: '记录id',hide:true},
                {field:'name', title:'业务模块名称',align : 'center' }
                ,{field:'type',align : 'center', title:'业务短信类型',templet:function(d){
                        return parseType(d.type);
                    }},
                {field:'explain', title:'申请说明',align : 'center' },
                {field:'createTime', title:'申请时间',align : 'center', sort: true,templet:function(d){
                        return formatTime(d.createTime);
                    } }
                ,{field:'applyUser', title:'申请人员', align : 'center' }
                ,{field:'isSetSign',align : 'center', title:'是否配置签名',templet:function(d){
                        return parseStatus(d.isSetSign);
                    }}
                ,{field:'isSetTemplate',align : 'center', title:'是否配置模板',templet:function(d){
                        return parseStatus(d.isSetTemplate);
                    }}
                ,{fixed: 'right', title:'操作', align : 'center',toolbar: '#barBusinessOperate',width:240}
            ]]
            ,page: true
        });
    }

    function renderSignTable(accountType){
        if(accountType == ACCOUNT_TYPE_TX){
            table.render({
                elem: '#smsSignTable2'
                ,url: '/cdsmsmgr/smsSign/list'
                ,method: 'get'
                ,where: {accountType:accountType}
                ,title: '签名管理'
                ,cols: [[
                    {type:'numbers',title: '序号'},
                    {field: 'id', title: '记录id',hide:true},
                    {field: 'accountType', title: '账号类型',hide:true},
                    {field:'signName', title:'签名名称',align : 'center' }
                    ,{field:'signId', title:'签名ID',align : 'center' }
                    ,{field:'status',align : 'center', title:'审核状态',templet:function(d){
                            return parseAuditStatus(d.status);
                        }},
                    {field:'reason', title:'审批备注',align : 'center' },
                    {field:'createTime', title:'申请时间',align : 'center', sort: true,templet:function(d){
                            return formatTime(d.createTime);
                        } }
                    ,{fixed: 'right', title:'操作', align : 'center',toolbar: '#barSignOperate',width:240}
                ]]
                ,page: true
            });
        }else {
            table.render({
                elem: '#smsSignTable2'
                ,url: '/cdsmsmgr/smsSign/list'
                ,method: 'get'
                ,where: {accountType:accountType}
                ,title: '签名管理'
                ,cols: [[
                    {type:'numbers',title: '序号'},
                    {field: 'id', title: '记录id',hide:true},
                    {field: 'accountType', title: '账号类型',hide:true},
                    {field:'signName', title:'签名名称',align : 'center' }
                    ,{field:'scene',align : 'center', title:'适用场景',templet:function(d){
                            return parseScene(d.scene);
                        }},
                    {field:'status',align : 'center', title:'审核状态',templet:function(d){
                            return parseAuditStatus(d.status);
                        }},
                    {field:'reason', title:'审批备注',align : 'center' },
                    {field:'createTime', title:'申请时间',align : 'center', sort: true,templet:function(d){
                            return formatTime(d.createTime);
                        } }
                    ,{fixed: 'right', title:'操作', align : 'center',toolbar: '#barSignOperate',width:240}
                ]]
                ,page: true
            });
        }
    }

    function renderTemplateTable(accountType){
        if(accountType == ACCOUNT_TYPE_TX){
            table.render({
                elem: '#smsTemplateTable2'
                ,url: '/cdsmsmgr/smsTemplate/list'
                ,method: 'get'
                ,where: {accountType:accountType}
                ,title: '模板记录'
                ,cols: [[
                    {type:'numbers',title: '序号'},
                    {field: 'id', title: '记录id',hide:true},
                    {field:'code', title:'模板ID',align : 'center' }
                    ,{field:'name', title:'模板名称',align : 'center' }
                    ,{field:'type',align : 'center', title:'模板类型',templet:function(d){
                            return parseType2(d.type);
                        }}
                    ,{field:'content', title:'模板内容',align : 'center' }
                    ,{field:'status',align : 'center', title:'审核状态',templet:function(d){
                            return parseAuditStatus(d.status);
                        }}
                    ,{field:'reason', title:'审核备注',align : 'center' }
                    ,{field:'createTime', title:'申请时间',align : 'center', sort: true,templet:function(d){
                            return formatTime(d.createTime);
                        } }
                    ,{fixed: 'right', title:'操作', align : 'center',toolbar: '#barTemplateperate',width:240}
                ]]
                ,page: true
            });
        }else {
            table.render({
                elem: '#smsTemplateTable2'
                ,url: '/cdsmsmgr/smsTemplate/list'
                ,method: 'get'
                ,where: {accountType:accountType}
                ,title: '模板记录'
                ,cols: [[
                    {type:'radio',title: ''},
                    {field: 'id', title: '记录id',hide:true},
                    {field:'name', title:'模板名称',align : 'center' }
                    ,{field:'code', title:'模板CODE',align : 'center' }
                    ,{field:'type',align : 'center', title:'模板类型',templet:function(d){
                            return parseType(d.type);
                        }}
                    ,{field:'content', title:'模板内容',align : 'center' }
                    ,{field:'status',align : 'center', title:'审核状态',templet:function(d){
                            return parseAuditStatus(d.status);
                        }}
                    ,{field:'createTime', title:'申请时间',align : 'center', sort: true,templet:function(d){
                            return formatTime(d.createTime);
                        } }
                    ,{field:'reason', title:'审核备注',align : 'center' }
                    ,{fixed: 'right', title:'操作', align : 'center',toolbar: '#barTemplateperate',width:240}
                ]]
                ,page: true
            });
        }
    }

    table.on('tool(smsBusinessTable)', function(obj){
        switch (obj.event) {
            case 'signSetting':
                setSign(obj.data.signId,obj.data.id);
                break;
            case 'templateSetting':
                setTemplate(obj.data.templateId,obj.data.id);
                break;
            case 'businessDelete':
                businessDelete(obj.data.id);
                break;
        }
    });

    function businessDelete(id){
        layer.confirm('确定要删除么?',function(){
            $.get("/cdsmsmgr/smsBusiness/delete", {"id":id}, function(data) {
                if (data.resultCode === '000') {
                    layer.msg('删除成功', {icon:1});
                    active1['reload'].call(this);
                    setTimeout(function () {
                        layer.closeAll();
                    },500);
                    return false;
                }
                layer.msg('删除失败',{icon:5});
            });
        });
    }

    table.on('tool(smsSignTable2)', function(obj){
        switch (obj.event) {
            case 'freshStatus':
                freshStatus(obj.data.id);
                break;
            case 'signDelete':
                deleteSign(obj.data.id);
                break;
            case 'signEdit':
                signEdit(obj.data);
                break;
        }
    });

    function signEdit(data) {
        let accountType = data.accountType;
        let contentId;
        if(accountType == ACCOUNT_TYPE_TX){//腾讯
            $("#documentType").empty().append(getOptions(data.source+''));
            form.render('select');
            form.val("applySmsSignForm2",data);
            $('#reason').removeClass('layui-hide').empty().append(data.reason);
            $("#uploadView").find("img").attr("alt",data.domainName);
            if(data.businessLicense){
                $('#uploadView').removeClass('layui-hide');
            }
            $("#uploadView").find("img").attr("src",data.businessLicense);
            contentId = "applySmsSignWindow2";
        }else {
            $('#reason1').removeClass('layui-hide').empty().append(data.reason);
            form.val("applySmsSignForm1",data);
            $.get("/cdsmsmgr/smsSign/queryImgsById", {"id":data.id}, function(res) {
                if (res.status == 200) {
                    let imgHtml = "";
                    $.each(res.data, function (index, item) {
                        imgHtml += '<img src="'+ item.content +'" alt="'+ item.name +'" width="100px" height="100px" class="layui-upload-img signFile">';
                    });
                    $('#fileList').empty().append(imgHtml);
                }
            });
            contentId = "applySmsSignWindow1";
        }
        form.render();
        layer.open({
            type: 1
            ,title: '修改签名'
            ,area: ['80%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#"+contentId)
        });
    }

    function freshStatus(id) {
        $.get("/cdsmsmgr/smsSign/freshStatus", {"id":id}, function(res) {
            if (res != null) {
                layer.msg(res.msg);
                setTimeout(function () {
                    table.reload('smsSignTable2',{page:{curr:1}});
                },500);
                return false;
            }
            layer.msg('刷新失败',{icon:5});
        });
    }

    function deleteSign(id) {
        layer.confirm('删除不会删除第三方平台短信服务中的签名,确定要删除么?',function(){
            var param = {"id":id};
            $.get("/cdsmsmgr/smsSign/delete",param, function(data) {
                if (data.resultCode === '000') {
                    layer.msg('删除成功', {icon:1});
                    active2['reload'].call(this);
                    setTimeout(function () {
                        layer.closeAll();
                    },500);
                    return false;
                }
                layer.msg('删除失败',{icon:5});
            });
        });
    }
    function setTemplate(templateId,businessId) {
        table.render({
            elem: '#smsTemplateTable'
            ,url: '/cdsmsmgr/smsTemplate/list'
            ,method: 'get'
            ,title: '模板记录'
            ,where: {status: 1,accountType:accountType} //审核通过的
            ,cols: [[
                {type:'radio',title: ''},
                {field: 'id', title: '记录id',hide:true},
                {field:'name', title:'模板名称',align : 'center' }
                ,{field:'code', title:'模板code',align : 'center' }
                ,{field:'type',align : 'center', title:'模板类型',templet:function(d){
                        return parseType(d.type);
                    }},
                {field:'content', title:'模板内容',align : 'center' }
                ,{field:'createTime', title:'申请时间',align : 'center', sort: true,templet:function(d){
                        return formatTime(d.createTime);
                    } }
            ]]
            ,done: function(res, curr, count){
                $.each(res.data, function (index, row) {
                    if (templateId && templateId === row['id']) {
                        row["LAY_CHECKED"] = 'true';
                        var _index = row['LAY_TABLE_INDEX'];
                        $(".layui-table-view[lay-id='smsTemplateTable'] .layui-table-body tr[data-index="+_index+"] .layui-form-radio").click();
                    }

                });

            }
            ,page: true
        });
        $("#businessId2").val(businessId);
        layer.open({
            type: 1
            ,title: '模板配置'
            ,area: ['90%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#chooseSmsTemplateWindow")
        });
    }
    function setSign(signId,businessId) {
        table.render({
            elem: '#smsSignTable'
            ,url: '/cdsmsmgr/smsSign/list'
            ,method: 'get'
            ,title: '签名记录'
             ,where: {status: 1,accountType:accountType} //审核通过的
            ,cols: [[
                {type:'radio',title: ''},
                {field: 'id', title: '记录id',hide:true},
                {field:'signName', title:'签名名称',align : 'center' }
                ,{field:'scene',align : 'center', title:'适用场景',templet:function(d){
                        return parseScene(d.scene);
                    }},
                {field:'createTime', title:'申请时间',align : 'center', sort: true,templet:function(d){
                        return formatTime(d.createTime);
                    } }
            ]]
            ,done: function(res, curr, count){
                $.each(res.data, function (index, row) {
                    if (signId && signId === row['id']) {
                        row["LAY_CHECKED"] = 'true';
                        var _index = row['LAY_TABLE_INDEX'];
                        $(".layui-table-view[lay-id='smsSignTable'] .layui-table-body tr[data-index="+_index+"] .layui-form-radio").click();
                    }

                });

            }
            ,page: true
        });
        $("#businessId").val(businessId);
        layer.open({
            type: 1
            ,title: '签名配置'
            ,area: ['66%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#chooseSmsSignWindow")
        });
    }
    form.on("submit(doChooseSmsSign)", function(data){
        var checkStatus = table.checkStatus('smsSignTable');
        var	arr = checkStatus.data;
        if(arr.length === 0){
            layer.msg("请选择签名!",{icon:5});
            return false;
        }
        layer.confirm('确认提交？', {
            btn: ['确认','取消']
        }, function(){
            data.field.signId = arr[0].id;
            data.field.isSetSign = 1;// 配置签名
            $.post("/cdsmsmgr/smsBusiness/saveInfo",data.field, function(result) {
                if(result.resultCode === '000' ){
                    layer.msg('保存成功', {icon: 1});
                    active1['reload'].call(this);
                    setTimeout(function () {
                        layer.closeAll();
                    },1000);
                }else{
                    layer.msg(result.resultDesc, {icon: 0});
                }
            });
        }, function(){
            layer.closeAll();
            return false;
        });
        return false;
    });
    form.on("submit(doChooseSmsTemp)", function(data){
        var checkStatus = table.checkStatus('smsTemplateTable');
        var	arr = checkStatus.data;
        if(arr.length === 0){
            layer.msg("请选择模板!",{icon:5});
            return false;
        }
        layer.confirm('确认提交？', {
            btn: ['确认','取消']
        }, function(){
            data.field.templateId = arr[0].id;
            data.field.isSetTemplate = 1;// 配置模板
            $.post("/cdsmsmgr/smsBusiness/saveInfo",data.field, function(result) {
                if(result.resultCode === '000' ){
                    layer.msg('保存成功', {icon: 1});
                    active1['reload'].call(this);
                    setTimeout(function () {
                        layer.closeAll();
                    },1000);
                }else{
                    layer.msg(result.resultDesc, {icon: 0});
                }
            });
        }, function(){
            layer.closeAll();
            return false;
        });
        return false;
    });

    $("#cancelChooseSmsSign").on('click',function () {
        layer.closeAll();
    });
    $("#cancelChooseSmsTem").on('click',function () {
        layer.closeAll();
    });

    $("#cancelApplySms").on('click',function () {
        layer.closeAll();
    });

    form.on("submit(doApplySms)", function(data){
        data.field.accountType = accountType;
        layer.confirm('确认提交？', {
            btn: ['确认','取消']
        }, function(){
            $.post("/cdsmsmgr/smsBusiness/saveInfo",data.field, function(result) {
                if(result.resultCode === '000' ){
                    layer.msg('保存成功', {icon: 1});
                    active1['reload'].call(this);
                    setTimeout(function () {
                        layer.closeAll();
                    },1000);
                }else{
                    layer.msg(result.resultDesc, {icon: 5});
                }
            });
        }, function(){
            layer.closeAll();
            return false;
        });
        return false;
    });

    function loadSmsBusinessList() {
        $.get('/cdsmsmgr/smsBusiness/loadSmsBusinessList', {dictType:"smsBusinessType"}, function (result) {
            if(result != null){
                if(result.data != null){
                    let arrayData = result.data;
                    if(result.data.data && $.isArray(result.data.data)){
                        arrayData = result.data.data;
                    }
                    var $opt_html = "<option value=''>请选择</option>";
                    $.each(arrayData, function (index, item) {
                        $opt_html += "<option value='" + item.dictName + "'>" + item.dictName + "</option>";
                    });
                    $("#businessName1").empty().append($opt_html);
                    form.render('select');
                }
            }
        });
    }
    function formatTime(time){
        if(time){
            return util.toDateString(time, "yyyy-MM-dd HH:mm:ss");
        }
        return "";
    }
    // 搜索业务名称
    form.on('submit(search)',function(data){
        active1['reload'].call(this);
        return false;
    });
    // 搜索标签名称
    form.on('submit(searchSign)',function(data){
        active2['reload'].call(this);
        return false;
    });
    // 签名查询
    form.on('submit(signSearch)',function(data){
        activeSign['reload'].call(this);
        return false;
    });
    // 同步签名
    let index;
    form.on('submit(syncSign)',function(data){
        if(accountType == 2){
            table.render({
                elem: '#syncSignTable'
                ,url: '/cdsmsmgr/smsSign/querySmsSignList'
                ,method: 'get'
                ,title: '同步签名管理'
                ,cols: [[
                    {type:'checkbox',title: ''},
                    {field: 'id', title: '记录id',hide:true},
                    {field:'signName', title:'签名名称',align : 'center' }
                    ,{field:'signId', title:'签名ID',align : 'center' },
                    {field:'status',title:'审核状态',align : 'center'},
                    {field:'reason', title:'审批备注',align : 'center' },
                    {field:'applyTime', title:'创建时间',align : 'center'}
                ]]
            });
        }else {
            table.render({
                elem: '#syncSignTable'
                ,url: '/cdsmsmgr/smsSign/querySmsSignList'
                ,method: 'get'
                ,title: '同步签名管理'
                ,cols: [[
                    {type:'checkbox',title: ''},
                    {field: 'id', title: '记录id',hide:true},
                    {field:'signName', title:'签名名称',align : 'center' }
                    ,{field:'scene',align : 'center', title:'适用场景',templet:function(d){
                            return parseScene(d.scene);
                        }},
                    {field:'status', title:'审核状态',align : 'center'},
                    {field:'reason', title:'审批备注',align : 'center' },
                    {field:'applyTime', title:'创建时间',align : 'center'}
                ]]
            });
        }
        index = layer.open({
            type: 1
            ,title: '同步签名'
            ,area: ['80%', '99%']
            ,shade: 0
            //,maxmin: true
            ,content:$("#syncSmsSignWindow")
        });
        return false;
    });
    // 同步模板
    form.on('submit(syncTemplateStatus)',function(data){
        if(accountType == ACCOUNT_TYPE_ALI){
            table.render({
                elem: '#syncTemplateTable'
                ,url: '/cdsmsmgr/smsTemplate/querySmsTemplateList'
                ,method: 'get'
                ,title: '同步模板管理'
                ,cols: [[
                    {type:'checkbox',title: ''},
                    {field: 'id', title: '记录id',hide:true},
                    {field:'templateName', title:'模板名称',align : 'center' }
                    ,{field:'templateId', title:'模板CODE',align : 'center' }
                    ,{field:'type', title:'模板类型',align : 'center' },
                    {field:'templateContent',title:'模板内容',align : 'center'},
                    {field:'status', title:'审核状态',align : 'center' },
                    {field:'reason', title:'审批备注',align : 'center' },
                    {field:'applyTime', title:'申请时间',align : 'center'}
                ]]
            });
        }else {
            table.render({
                elem: '#syncTemplateTable'
                ,url: '/cdsmsmgr/smsTemplate/querySmsTemplateList'
                ,method: 'get'
                ,title: '同步模板管理'
                ,cols: [[
                    {type:'checkbox',title: ''},
                    {field: 'id', title: '记录id',hide:true},
                    {field:'templateName', title:'模板名称',align : 'center' }
                    ,{field:'templateId', title:'模板ID',align : 'center' }
                    ,{field:'type', title:'模板类型',align : 'center' },
                    {field:'templateContent',title:'模板内容',align : 'center'},
                    {field:'status', title:'审核状态',align : 'center' },
                    {field:'reason', title:'审批备注',align : 'center' },
                    {field:'applyTime', title:'申请时间',align : 'center'}
                ]]
            });
        }
        layer.open({
            type: 1
            ,title: '同步模板'
            ,area: ['80%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#syncSmsTemWindow")
        });
        return false;
    });
    // 同步签名保存
    form.on('submit(doChooseSyncSmsSign)',function(res){
        let checkStatus = table.checkStatus('syncSignTable');
        let data= checkStatus.data
        if(data.length == 0){
            layer.msg("请选择需要同步的签名");
            return false;
        }
        let arr = [];
        for(let i in data){
            let obj = data[i];
            obj.type = accountType;
            arr[i] = obj;
        }
        $.ajax({
            type: 'post',
            url: '/cdsmsmgr/smsSign/syncSmsSign',
            contentType: "application/json;charset=utf-8",
            dataType: 'json',
            data: JSON.stringify(arr),
            success: function (res) {
                layer.msg(res.msg);
                setTimeout(function (){
                    layer.closeAll();
                },1000);
                table.reload('smsSignTable2',{page:{curr:1}});
            },
        });
        return false;
    });

    // 同步模板保存
    form.on('submit(doChooseSyncSmsTem)',function(res){
        let checkStatus = table.checkStatus('syncTemplateTable');
        let data= checkStatus.data
        if(data.length == 0){
            layer.msg("请选择需要同步的模板");
            return false;
        }
        let arr = [];
        for(let i in data){
            let obj = data[i];
            obj.accountType = accountType;
            arr[i] = obj;
        }
        $.ajax({
            type: 'post',
            url: '/cdsmsmgr/smsTemplate/syncSmsTemp',
            contentType: "application/json;charset=utf-8",
            dataType: 'json',
            data: JSON.stringify(arr),
            success: function (res) {
                layer.msg(res.msg);
                setTimeout(function (){
                    layer.closeAll();
                },1000);
                table.reload('smsTemplateTable2',{page:{curr:1}});
            },
        });
        return false;
    });

    // 申请签名弹窗
    form.on('submit(applySign)',function(data){
        let contentId;
        if(accountType == 2){//腾讯
            resetForm('applySmsSignForm2');
            $("#uploadView").find("img").attr("src","");
            $("#reason").empty();
            $("#reason").addClass("layui-hide");
            contentId = "applySmsSignWindow2";
        }else {
            resetForm('applySmsSignForm1');
            $("#fileList").empty();
            $("#reason1").empty();
            $("#reason1").addClass("layui-hide");
            contentId = "applySmsSignWindow1";
        }
        layer.open({
            type: 1
            ,title: '申请签名'
            ,area: ['80%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#"+contentId)
        });
        return false;
    });

    $("#cancelChooseSyncSmsSign").on('click',function () {
        layer.close(index);
    });

    $("#cancelChooseSyncSmsTem").on('click',function () {
        layer.closeAll();
    });

    // 搜索模板名称
    form.on('submit(templateSearch)',function(data){
        activeTemplate['reload'].call(this);
        return false;
    });
    form.on('submit(searchTemplate)',function(data){
        active3['reload'].call(this);
        return false;
    });
    form.on('submit(applaySms)',function(data){
        resetForm('applySmsForm');
        layer.open({
            type: 1
            ,title: '添加短信业务'
            ,area: ['66%', '69%']
            ,shadeClose: true
            ,content:$("#applySmsWindow")
        });
        return false;
    });
    form.on('submit(addSign)',function(data){
        resetForm('addSmsSignForm');
        if(accountType == ACCOUNT_TYPE_TX){
            $("#signIdDiv").removeClass("layui-hide");
        }else {
            $("#signIdDiv").addClass("layui-hide");
        }
        layer.open({
            type: 1
            ,title: '添加签名'
            ,area: ['66%', '69%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#addSmsSignWindow")
        });
        return false;
    });
    form.on('submit(applayTemplate)',function(data){
        let contentId;
        if(accountType == ACCOUNT_TYPE_TX){//腾讯
            resetForm('applySmsTemplateFormTx');
            $("#reasonTemp2").empty();
            $("#reasonTemp2").addClass("layui-hide");
            contentId = "applySmsTemplateWindowTx";
        }else {
            resetForm('applySmsTemplateForm');
            $("#reasonTemp1").empty();
            $("#reasonTemp1").addClass("layui-hide");
            contentId = "applySmsTemplateWindow";
        }
        layer.open({
            type: 1
            ,title: '申请模板'
            ,area: ['66%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#"+contentId)
        });
        return false;
    });
    form.on('submit(addTemplate)',function(data){
        let contentId;
        if(ACCOUNT_TYPE_TX == accountType){
            resetForm('addSmsTemplateFormTx');
            contentId = "addSmsTemplateWindowTx";
        }else {
            resetForm('addSmsTemplateForm');
            contentId = "addSmsTemplateWindow";
        }
        layer.open({
            type: 1
            ,title: '添加模板'
            ,area: ['66%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#"+contentId)
        });
        return false;
    });
    var active1 = {
        reload:function () {
            var name = $("#businessName").val();
            table.reload('smsBusinessTable', {
                where: {name:name,accountType:accountType},page: {curr:1}
            }, 'data');
        }
    };
    var active2 = {
        reload:function () {
            var name = $("#signNameMgr").val();
            table.reload('smsSignTable2', {
                where: {name:name,accountType:accountType},page: {curr:1}
            }, 'data');
        }
    };
    var active3 = {
        reload:function () {
            var name = $("#templateNameMgr").val();
            var type = $("#templateType").val();
            table.reload('smsTemplateTable2', {
                where: {name:name,type:type,accountType:accountType},page: {curr:1}
            }, 'data');
        }
    };
    var activeSign = {
        reload:function () {
            var name = $("#signName").val();
            table.reload('smsSignTable', {
                where: {name:name},page: {curr:1}
            }, 'data');
        }
    };
    var activeTemplate = {
        reload:function () {
            var name = $("#templateName").val();
            table.reload('smsTemplateTable', {
                where: {name:name,accountType:accountType},page: {curr:1}
            }, 'data');
        }
    };
    //自定义验证规则
    form.verify({
        fname: function(value){
            if(value.length > 12|| value.length < 2){
                return '请输入2-12个字符';
            }
        },
        fname2: function(value){
            if(value.length > 30){
                return '模板名称不超过30个字符';
            }
        },
        content: function(value){
            if(value.length > 500){
                return '模板内容不超过500个字符';
            }
        },
        content2: function(value){
            if(value.length > 490){
                return '模板内容不超过490个字符';
            }
        },
        explain: function(value){
            if(value.length > 200){
                return '请输入200个一下字符';
            }
        },
        explain2: function(value){
            if(value.length > 100){
                return '申请说明不超过100个字符';
            }
        },
        explain3: function(value){
            if(value.length > 300){
                return '模板备注不超过300个字符';
            }
        }
    });
    // 阿里文件上传
    upload.render({
        elem: '#uploadFile'
        ,url: '/cdsmsmgr/smsSign/fakeUploadFile' //此处配置你自己的上传接口即可
        ,multiple: true
        ,size: 2048 // 图片不超过2MB
        ,accept: 'images'
        ,acceptMime:'image/jpg, image/png, image/gif, image/jpeg'
        ,exts: 'jpg|png|gif|jpeg'
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#fileList').append('<img src="'+ result +'" alt="'+ file.name +'" width="100px" height="100px" class="layui-upload-img signFile">')
            });
        }
        ,done: function(res){
            //上传完毕
        }
    });
    // 移除图片
    $("#removeFile").on("click",function () {
        $('#fileList').empty();
    });

    // 腾讯文件上传
    upload.render({
        elem: '#uploadFile2'
        ,url: '/cdsmsmgr/smsSign/fakeUploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#uploadView').removeClass('layui-hide').find('img').attr('src', result);
            });
        }
        ,done: function(res){
            //layer.msg('上传成功');
        }
    });

    uploadFile('businessLicense','uploadLiceView','businessLicenseType');
    uploadFile('powerOfAttorney','uploadPotView','powerOfAttorneyType');
    uploadFile('businessLicense2','uploadLiceView2','businessLicenseType2');
    uploadFile('orgInstBarCode','uploadIbcView','orgInstBarCodeType');
    uploadFile('taxRegistCertifi','uploadRcView','taxRegistCertifiType');
    uploadFile('powerOfAttorney2','uploadPotView2','powerOfAttorneyType2');
    function uploadFile(eleId, viewId,typeId){
        upload.render({
            elem: '#'+eleId
            ,url: '/cdsmsmgr/smsSign/uploadFiles'
            ,size: 2048 //限制文件大小，单位 KB
            ,acceptMime: 'image/*'
            ,ext: 'jpg|png|gif|jpeg'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    var fileType = file.type.replace('image/','');
                    $('#'+viewId).find('img').attr('src', result); //图片链接（base64）
                    $('#'+typeId).val(fileType);
                });
            }
            ,done: function(res){
                if(res && res.code === 200){
                    layer.msg('上传成功',{icon:1});
                    layui.$('#'+viewId).removeClass('layui-hide');
                }
            }
        });
    }

    function isNumber(val){
        let reg = /^[1-9][0-9]+$/gi;
        return reg.test(val);
    }

    // 添加申请提交
    form.on("submit(doAddSmsSign)", function(data){
        if(!isNumber($("#signIdAdd").val()) && ACCOUNT_TYPE_TX == accountType){
            layer.msg("签名id是数字额",{icon:5});
            return false;
        }
        data.field.accountType = accountType;
        layer.confirm('确认提交？', {
            btn: ['确认','取消']
        }, function(){
            var loading = layer.load(0, {
                shade: false,
                time: 2*1000
            });
            $.post("/cdsmsmgr/smsSign/addSmsSign",data.field, function(result) {
                if(result.resultCode === '000' ){
                    layer.msg('保存成功', {icon: 1});
                    active2['reload'].call(this);
                    setTimeout(function () {
                        layer.closeAll();
                    },1000);
                }else{
                    layer.msg(result.resultDesc, {icon: 0});
                }
            });
        }, function(){
            layer.closeAll();
            return false;
        });
        return false;
    });

    form.on('select(signType)', function(data){
        let val = data.value;
        $("#documentType").empty().append(getOptions(val));
        form.render('select');
    });

    function getOptions(val) {
        let options;
        switch (val) {
            case "0"://0：公司，可选 DocumentType 有（0，1）。
                options = generateOption([0,1]);
                break;
            case "1"://1：APP，可选 DocumentType 有（0，1，2，3，4） 。
                options = generateOption([0,1,2,3,4]);
                break;
            case "2"://2：网站，可选 DocumentType 有（0，1，2，3，5）。
                options = generateOption([0,1,2,3,5]);
                break;
            case "3"://3：公众号，可选 DocumentType 有（0，1，2，3，8）
                options = generateOption([0,1,2,3,8]);
                break;
            case "4"://4：商标，可选 DocumentType 有（7）
                options = generateOption([7]);
                break;
            case "5"://5：政府/机关事业单位/其他机构，可选 DocumentType 有（2，3）。
                options = generateOption([2,3]);
                break;
            case "6"://6：小程序，可选 DocumentType 有（0，1，2，3，6）。
                options = generateOption([0,1,2,3,6]);
                break;
            default:
                options = "<option value=''></option>";
                break;
        }
        return options;
    }

    function generateOption(arr){
        let options = "<option value=''></option>";
        $.each(docTypeArr, function (index, item) {
            let key = item.key;
            if($.inArray(key,arr) >= 0){
                options += "<option value='" + key + "'>" + item.value + "</option>";
            }
        });
        return options;
    }

    // 阿里 签名申请提交
    form.on("submit(doApplyAliSmsSign)", function(data){
        let len = $(".signFile").length;
        if(len == 0){
            layer.msg("请上传证明文件",{icon:5});
            return false;
        }
        let fileList = [];
        $(".signFile").each(function () {
            fileList.push({"name":$(this).attr("alt"),"content":$(this).attr("src")});
        });
        data.field.fileList = fileList;
        layer.confirm('确认提交？', {
            btn: ['确认','取消']
        }, function(){
            var loading = layer.load(0, {
                shade: false,
                time: 2*1000
            });
            $.ajax({
                url: "/cdsmsmgr/smsSign/applyAliSmsSign",
                type: "post",
                contentType: "application/json;charset=utf-8",
                dataType: 'json',
                data: JSON.stringify(data.field),
                success: function (data) {
                    if(data.status === 200 ){
                        layer.msg(data.msg, {icon: 1});
                        active2['reload'].call(this);
                        setTimeout(function () {
                            layer.closeAll();
                        },1000);
                    }else{
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 5});
                    }
                }
            });
        }, function(index){
            layer.close(index);
            return false;
        });
        return false;
    });

    // 腾讯 签名申请提交
    form.on("submit(doApplyTxSmsSign)", function(data){
        let src = $("#uploadView").find("img").attr("src");
        if(!src){
            layer.msg("请上传证明图片",{icon:5});
            return false;
        }
        data.field.proofImage = src;
        layer.confirm('确认提交？', {
            btn: ['确认','取消']
        }, function(){
            var loading = layer.load(0, {
                shade: false,
                time: 2*1000
            });
            $.ajax({
                url: "/cdsmsmgr/smsSign/applyTxSmsSign",
                type: "post",
                contentType: "application/json;charset=utf-8",
                dataType: 'json',
                data: JSON.stringify(data.field),
                success: function (data) {
                    if(data.status === 200 ){
                        layer.msg(data.msg, {icon: 1});
                        active2['reload'].call(this);
                        setTimeout(function () {
                            layer.closeAll();
                        },1000);
                    }else{
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 5});
                    }
                }
            });
        }, function(index){
            layer.close(index);
            return false;
        });
        return false;
    });

    $("#cancelAddSmsSign").on('click',function () {
        layer.closeAll();
    });
    $("#cancelAliApplySmsSign").on('click',function () {
        layer.closeAll();
    });
    $("#cancelTxApplySmsSign").on('click',function () {
        layer.closeAll();
    });
    $("#cancelApplySmsTemp").on('click',function () {
        layer.closeAll();
    });
    $("#cancelApplySmsTempTx").on('click',function () {
        layer.closeAll();
    });
    $("#cancelAddSmsTemp").on('click',function () {
        layer.closeAll(); //取消添加模板
    });
    $("#cancelAddSmsTempTx").on('click',function () {
        layer.closeAll(); //取消添加模板
    });

    form.on("radio(templateType)", function (data) {
        changeTemplateType(data.value);
    });

    function changeTemplateType(val){
        if(val === '0'){ // 验证码
            $("#commonTemplate").show();
            $("#vercodeTip1").empty().append("● 变量限制：仅支持1个验证码作为变量；4~6位仅数字、数字+字母组合或仅字母2种类型。");
            $("#vercodeTip2").empty().append("● 变量格式：${code}；例如：您的验证码为 ${code} ，该验证码5分钟内有效，请勿泄露于他人。");
            $("#vercodeTip2").show();
        }else  if(val === '1'){ // 短信通知
            $("#commonTemplate").show();
            $("#vercodeTip1").empty().append("● 变量限制：不支持QQ号、微信号、网址信息；1~35位字符，但电话号码支持5~11位");
            $("#vercodeTip2").show();
            $("#vercodeTip2").empty().append("● 变量格式：${name}；例如，尊敬的 ${name}，您的快递已飞奔在路上，将今天 ${time} 送达您的手里，请留意查收。");
        }else { //推广短信
            $("#commonTemplate").hide();
            $("#vercodeTip1").empty().append("● 变量限制：推广短信及群发助手不支持加变量");
            $("#vercodeTip2").hide();
        }
    }


    form.on("radio(templateTypeTx)", function (data) {
        changeTemplateTypeTx(data.value);
    });

    function changeTemplateTypeTx(val){
        if(val === '0'){ // 普通短信
            $("#stardardTemplateDiv").show();
        }else {
            $("#stardardTemplateDiv").hide();
        }
    }

    // 阿里 常用模板
    $("#commonTemplates").on('click',function () {
        var type = $("#templateTypeDiv input[name='type']:checked").val();
        var verifCodeData = [{
            "type": "验证码"
            ,"content": "您正在申请手机注册，验证码为：${code}，5分钟内有效！"
        }, {
            "type": "验证码"
            ,"content": "尊敬的用户，您的注册会员动态密码为：${code}，请勿泄漏于他人！"
        }, {
            "type": "验证码"
            ,"content": "您的动态码为：${code}，您正在进行密码重置操作，如非本人操作，请忽略本短信！"
        }, {
            "type": "验证码"
            ,"content": "您的验证码${code}，该验证码5分钟内有效，请勿泄漏于他人！"
        }, {
            "type": "验证码"
            ,"content": "您的验证码：${code}，您正进行身份验证，打死不告诉别人！"
        }, {
            "type": "验证码"
            ,"content": "您的注册码：${code}，如非本人操作，请忽略本短信！"
        }, {
            "type": "验证码"
            ,"content": "您的校验码：${code}，您正在注册成为会员，感谢您的支持！"
        }, {
            "type": "验证码"
            ,"content": "验证码为：${code}，您正在登录，若非本人操作，请勿泄露。"
        }, {
            "type": "验证码"
            ,"content": "验证码为：${code}，您正在尝试变更重要信息，请妥善保管账户信息。"
        }, {
            "type": "验证码"
            ,"content": "验证码为：${code}，您正在注册成为平台会员，感谢您的支持！"
        }];
        if(type === "1"){
            verifCodeData = [{
                "type": "短信通知"
                ,"content": "您好，您的密码已经重置为${password}，请及时登录并修改密码。"
            }, {
                "type": "短信通知"
                ,"content": "您的${mtname}申请已于${submittime}审批通过，特此通知。"
            }, {
                "type": "短信通知"
                ,"content": "您的兑换申请已经通过，兑换码为${code}，请勿告诉别人！"
            }, {
                "type": "短信通知"
                ,"content": "您有新的订单待处理，当前状态：${status}，订单摘要:${remark}，请及时处理。"
            }, {
                "type": "短信通知"
                ,"content": "您有新的${product}订单，请注意查收！"
            }, {
                "type": "短信通知"
                ,"content": "尊敬的${name}, 门店${store}有新的配送订单,快去抢单！"
            }, {
                "type": "短信通知"
                ,"content": "尊敬的${name}用户，您的提货码是：${code}，请不要把提货码泄露给其他人。"
            }, {
                "type": "短信通知"
                ,"content": "您有新订单，收货人：${consignee}，联系方式：${number}，请您及时查收！"
            }, {
                "type": "短信通知"
                ,"content": "亲爱的会员，您在${name}的订单提交成功。我们会尽快发货，记得关注我们的商城喔~感谢您的支持！"
            }, {
                "type": "短信通知"
                ,"content": "您好，请凭取件码：${code}，至${address}取件，若有问题请咨询${phone}。"
            }];
        }
        table.render({
            elem: '#commonTemplatesTable'
            ,cols: [[
                {field: 'type', align : 'center',title: '模板类型', width: 150}
                ,{field: 'content', title: '模板内容', align : 'center', width: 500}
                ,{fixed: 'right', title:'操作', align : 'center',toolbar: '#chooseTemplateOperate', width: 200}
            ]]
            ,data: verifCodeData
        });
        commonTemWindow = layer.open({
            type: 1
            ,title: '常用模板库'
            ,area: ['66%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#commonTemplatesWindow")
        });
    });
    var commonTemWindow;
    table.on('tool(commonTemplatesTable)', function(obj){
        switch (obj.event) {
            case 'chooseTemplate':
                $("#templateContent").val(obj.data.content);
                layer.close(commonTemWindow);
                break;
            case '':
                break;
        }
    });

    // 腾讯标准模板
    $("#useStardardTemplate").on('click',function () {
        var templateData = [{
            "content": "验证码为：{1}，您正在登录，若非本人操作，请勿泄露。"
        }, {
            "content": "{1}为您的登录验证码，请于{2}分钟内填写，如非本人操作，请忽略本短信。"
        },{
            "content": "您正在申请手机注册，验证码为：{1}，{2}分钟内有效！"
        },{
            "content": "您的动态验证码为：{1}，您正在进行密码重置操作，如非本人操作，请忽略本短信！"
        },{
            "content": "您的注册验证码：{1}，如非本人操作，请忽略本短信！"
        },{
            "content": "您正在修改注册手机号码，验证码为：{1}，5分钟有效，为保障帐户安全，请勿向任何人提供此验证码。"
        }];
        table.render({
            elem: '#stardTemplatesTable'
            ,cols: [[
                {field: 'content', title: '模板内容', align : 'center', width: 500}
                ,{fixed: 'right', title:'操作', align : 'center',toolbar: '#chooseTemplateOperate', width: 300}
            ]]
            ,data: templateData
        });
        stardardTemplateWindow = layer.open({
            type: 1
            ,title: '使用标准模板'
            ,area: ['66%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#commonTemplatesWindowTx")
        });
    });
    let stardardTemplateWindow;
    table.on('tool(stardTemplatesTable)', function(obj){
        switch (obj.event) {
            case 'chooseTemplate':
                $("#templateContentTx").val(obj.data.content);
                layer.close(stardardTemplateWindow);
                break;
        }
    });
    // 阿里申请模板
    form.on("submit(doApplySmsTemplate)", function(data){
        data.field.accountType = ACCOUNT_TYPE_ALI;
        submitTemplate(data.field);
        return false;
    });

    // 腾讯申请模板
    form.on("submit(doApplySmsTemplateTx)", function(data){
        data.field.accountType = ACCOUNT_TYPE_TX;
        submitTemplate(data.field);
        return false;
    });

    function submitTemplate(fields){
        layer.confirm('确认提交？', {
            btn: ['确认','取消']
        }, function(){
            var loading = layer.load(0, {
                shade: false,
                time: 2*1000
            });
            $.post("/cdsmsmgr/smsTemplate/appSmsTemplate",fields, function(result) {
                if(result.resultCode === '000' ){
                    layer.msg('提交成功', {icon: 1});
                    active3['reload'].call(this);
                    setTimeout(function () {
                        layer.closeAll();
                    },1000);
                }else{
                    layer.msg(result.resultDesc, {icon: 5});
                    setTimeout(function () {
                        layer.close(loading);
                    },1000);
                }
            });
        }, function(){
            layer.closeAll();
            return false;
        });
    }

    // 阿里添加模板
    form.on("submit(doAddSmsTemplate)", function(data){
        data.field.accountType = ACCOUNT_TYPE_ALI;
        submitAddTemplate(data.field);
        return false;
    });

    // 腾讯添加模板
    form.on("submit(doAddSmsTemplateTx)", function(data){
        data.field.accountType = ACCOUNT_TYPE_TX;
        submitAddTemplate(data.field);
        return false;
    });

    function submitAddTemplate(fields){
        layer.confirm('确认提交？', {
            btn: ['确认','取消']
        }, function(){
            var loading = layer.load(0, {
                shade: false,
                time: 2*1000
            });
            $.post("/cdsmsmgr/smsTemplate/saveInfo",fields, function(result) {
                if(result.resultCode === '000' ){
                    layer.msg('提交成功', {icon: 1});
                    active3['reload'].call(this);
                    setTimeout(function () {
                        layer.closeAll();
                    },1000);
                }else{
                    layer.msg(result.resultDesc, {icon: 5});
                    setTimeout(function () {
                        layer.close(loading);
                    },1000);
                }
            });
        }, function(){
            layer.closeAll();
            return false;
        });
    }

    // 同步模板状态
    // form.on("submit(syncTemplateStatus)", function(data){
    //     layer.confirm('确认同步？', {
    //         btn: ['确认','取消']
    //     }, function(){
    //         var loading = layer.load(0, {
    //             shade: false,
    //             time: 2*1000
    //         });
    //         $.post("/cdsmsmgr/smsTemplate/syncTemplateStatus",{}, function(result) {
    //             if(result.resultCode === '000' ){
    //                 layer.msg(result.resultDesc, {icon: 1});
    //                 active3['reload'].call(this);
    //                 setTimeout(function () {
    //                     layer.closeAll();
    //                     layer.close(loading);
    //                 },1000);
    //             }else{
    //                 layer.msg(result.resultDesc, {icon: 5});
    //                 setTimeout(function () {
    //                     layer.close(loading);
    //                 },1000);
    //             }
    //         });
    //     }, function(){
    //         layer.closeAll();
    //         return false;
    //     });
    //     return false;
    // });

    table.on('tool(smsTemplateTable2)', function(obj){
        switch (obj.event) {
            // case 'templateDetail':
            //     templateDetail(obj.data);
            //     break;
            case 'freshStatus':
                freshTemplateStatus(obj.data.id);
                break;
            case 'templateEdit':
                templateEdit(obj.data);
                break;
            case 'templateDelete':
                templateDelete(obj.data.id);
                break;
        }
    });

    function freshTemplateStatus(id) {
        var loading = layer.load(0, {
            shade: false,
            time: 2*1000
        });
        $.get("/cdsmsmgr/smsTemplate/freshStatus", {"id":id}, function(res) {
            if (res.status == 200 ) {
                layer.msg(res.msg,{icon:1});
                setTimeout(function () {
                    table.reload('smsTemplateTable2',{page:{curr:1}});
                },500);
                return false;
            }else {
                layer.msg(res.msg,{icon:5});
            }
            layer.close(loading);
        });
    }

    function templateDetail(data) {
        $("#templateType2").empty().append(parseType(data.type));
        $("#templateName2").empty().append(data.name);
        $("#templateCode2").empty().append(data.code);
        $("#templateContent2").empty().append(data.content);
        $("#templateExplain2").empty().append(data.explain);
        layer.open({
            type: 1
            ,title: '模板详情'
            ,area: ['60%', '69%']
            ,shade: 0
            ,maxmin: true
            ,btn: ['确定', '关闭']
            ,content:$("#templateDetailWindow")
        });
    }
    function templateEdit(data) {
        let type = data.accountType;
        let contentId;
        if(ACCOUNT_TYPE_ALI == type){
            $("#reasonTemp1").removeClass("layui-hide");
            $("#reasonTemp1").empty().append("不通过原因: " + data.reason);
            form.val("applySmsTemplateForm",data);
            changeTemplateType(data.type);
            contentId = "applySmsTemplateWindow";
        }else {
            $("#reasonTemp2").removeClass("layui-hide");
            $("#reasonTemp2").empty().append("不通过原因: " + data.reason);
            form.val("applySmsTemplateFormTx",data);
            changeTemplateTypeTx(data.type);
            contentId = "applySmsTemplateWindowTx";
        }
        // $("#templateId").val(data.id);
        // $("#templateCode").val(data.code);
        // $("#templateTypeDiv [name='type'][value="+data.type+"]").prop("checked", "checked");
        // $("#templateNameEdit").val(data.name);
        // $("#templateNameEdit").val(data.name);
        // $("#templateContent").val(data.content);
        // $("#templateExplain").val(data.explain);
        form.render();
        layer.open({
            type: 1
            ,title: '修改模板'
            ,area: ['66%', '99%']
            ,shade: 0
            ,maxmin: true
            ,content:$("#"+contentId)
        });
    }
    function templateDelete(id) {
        layer.load(0, {
            shade: false,
            time: 2*1000
        });
        layer.confirm('确定要删除么?',function(){
            $.get("/cdsmsmgr/smsTemplate/delete",{"id":id}, function(data) {
                if (data.resultCode === '000') {
                    layer.msg('删除成功', {icon:1});
                    active3['reload'].call(this);
                    setTimeout(function () {
                        layer.closeAll();
                    },500);
                    return false;
                }
                layer.msg('删除失败',{icon:5});
            });
        });
    }

    function resetForm(formId){
        $("#"+formId).find('input[type=text],input[type=number],input[type=hidden],textarea').each(function() {
            $(this).val('');
        });
    }

});

function parseType(type) {
    switch (type) {
        case 0: return '验证码';
        case 1: return '短信通知';
        case 2: return '推广短信';
        case 3: return '国际/港澳台消息';
        default: return '-';
    }
}

function parseType2(type) {
    switch (type) {
        case 0: return '普通短信';
        case 1: return '营销短信';
        default: return '-';
    }
}
function parseStatus(status) {
    switch (status) {
        case 0: return "否";
        case 1: return "是";
        default: return '-';
    }
}
function parseAuditStatus(status) {
    switch (status) {
        case 0: return "审核中";
        case 1: return "审核通过";
        case 2: return "审核失败";
        default: return '-';
    }
}
function parseScene(scene) {
    switch (scene) {
        case 0: return '验证码';
        case 1: return '通用';
        default: return '-';
    }
}
